/**
 * Created by yjy on 2017/2/28.
 */

export default class CSS {
    static width() {
        return window.screen.width;
    }

    static height() {
        return window.screen.height;
    }

    static pixel(pixel) {
        return pixel/12 + 'rem'
    }

    static parseBackgroundImage(image) {
        return 'url(' + image + ')'
    }

    static textLimit(str = '', number) {
        if(str.length > number) {
            return str.substring(0, number) + '...';
        }
        return str;
    }

    static parseTime(time) {
        let [year, month, day] = time.split('-');
        let date = new Date();
        date.setDate(day);
        date.setMonth(month - 1);
        date.setFullYear(year);
        return date.getTime();
    }

    static parseHtml(html = '') {
        let str = html.replace( /<[^>]+>/g, "" );
        str = str.replace( /(&amp;)/g,  "&" );
        str = str.replace( /(&lt;)/g ,  "<" );
        str = str.replace( /(&gt;)/g ,  ">" );
        str = str.replace( /(&nbsp;)/g ,  " " );
        return str;
    }
}